<?php

!defined('IN_APP') && exit('Access Denied');

class admin_fieldcontrol extends controlbase {


    function ondefault($msg='') {
         $userfieldlist = $this('userfield')->findAll();
          include template('userfieldlist');
    }

   /*启用和禁用字段*/
    function onenable() {
		$id=intval($this->get['id']);
		$state=intval($this->get['state']);
		$this('userfield')->update(array('id'=>$id ),array('state'=>$state));
		$this->message('操作成功!','c=admin_field');
    }


   /*排序字段*/
    function onorder() {
		$orderstr=substr($this->post['order'],0,-1);
		$this('userfield')->order($orderstr);
    }
     
    function onadd() {
        if (isset($this->post['submit'])) {
			$userfield = $this->post;
			$fieldname=$this->post['name'];
			$finduserfield=$this('userfield')->findByName($fieldname);
			if($finduserfield) $this->message("字段 $fieldname 已经存在!", 'c=admin_field&a=add');
			unset($userfield['submit']);
			$userfield['state']=intval($userfield['state']);
			$this('userfield')->insert($userfield);//保存个人信息
			$this->message('添加字段成功!','c=admin_field');
        }
        include template('addfield');
    }
    
    function onedit() {
		$id = intval($this->get['id']);
		if (isset($this->post['submit'])) {
			$userfield = $this->post;
			unset($userfield['submit']);
			$this('userfield')->update(array('id'=>$id ), $userfield);//保存个人信息
			$this->message("编辑成功", 'c=admin_field');
        }
		$userfield = $this('userfield')->findById($id);
	    include template('editfield');
    }

     function onremove() {
		$id = intval($this->get['id']);
		$this('userfield')->remove(array('id'=>$id ));
		$this->message("删除成功", 'c=admin_field');
    }


}
